<script>
	import {
		openidLogin,
		user_info
	} from "@/api/user";
	export default {
		onLaunch: function() {
			const that = this
			const locale = uni.getStorageSync('locale') || 'zh'
			this.$i18n.locale = locale;
			uni.setStorageSync('locale', locale)
			
			if (wx.canIUse("getUpdateManager")) {
				const updateManager = wx.getUpdateManager();
				updateManager.onCheckForUpdate(function(res) {
					// 请求完新版本信息的回调
					console.log(res.hasUpdate,'res.hasUpdate')
					if (res.hasUpdate) {
						updateManager.onUpdateFailed(function() {
							wx.showModal({
								title: '新版本下载失败',
								content: '请删除当前小程序，重启搜索打开...',
							})
						});
						updateManager.onUpdateReady(function() {
							wx.showModal({
								title: '更新提示',
								content: '新版本已经下载好，是否重启当前应用？',
								success(res) {
									if (res.confirm) {
										updateManager.applyUpdate()
									}
								}
							})
						})
						updateManager.onUpdateFailed(function() {
							wx.showModal({
								title: '发现新版本',
								content: '请删除当前小程序，重启搜索打开...',
							})
						})
					}
				})
			} else {
				wx.showModal({
					title: "更新提示",
					content: "当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。"
				});
			} 
		},
		onShow() {
			// let token = uni.getStorageSync('token');
			// if (!token) {
			// 	that.onOpenidLogin()
			// }
		},
		methods: {
			onOpenidLogin() {
				const t = this
				uni.login({
					success: async (code_res) => {
						const code_data = await openidLogin({code: code_res.code})
						// const code_data = await test_login({user_id: 91})
						uni.hideLoading()
						if(code_data.code == 200) {
							uni.setStorageSync('token', code_data.token)
							uni.setStorageSync('userName', code_data.data.name)
							uni.setStorageSync('englishname', code_data.data.english_name)
							uni.reLaunch({
								url: '/pages/indexBox/meetList'
							})
						} else {
							uni.reLaunch({
								url: '/pages/login/wxLogin'
							})
							// uni.showToast({
							// 	icon: 'none',
							// 	title: '登录失败!',
							// 	duration: 0
							// })
						}
					}
				})
			}
		},
		onShow: function() {},
		onHide() {}
	}
</script>

<style lang="scss">
	@import url("@/components/u-parse/u-parse.css");
	uni-nav-bar {
	  position: relative;
		z-index: 99999999 !important;
	}
	.uni-nav-bar-text {
		font-size: 30upx !important;
		font-weight: bold;
	}
	
	.uni-calendar-item__weeks-box .uni-calendar-item--checked, .uni-calendar-item--multiple .uni-calendar-item--before-checked, .uni-calendar-item--multiple .uni-calendar-item--after-checked {
		background-color: #d3a86a !important;
	}
	.uni-datetime-picker--btn {
		background-color: #d3a86a !important;
	}
	.uni-date-editor--x__disabled {
		opacity: 1 !important;
	}
	rich-text {
		word-break: break-all;
		white-space: pre-line;
	}
	.wxParse {
		color: #fff !important;
	}
	
</style>
